<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title>历史通知/公告</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <!-- Layui样式 -->
  <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
  <script th:src="@{/layui/layui.js}"></script>

  <style>
    .main-container {
      max-width: 1200px;
      margin: 20px auto;
      padding: 20px;
      background: #fff;
      border-radius: 8px;
      box-shadow: 0 2px 15px rgba(0,0,0,0.1);
    }

    .layui-table {
      margin-top: 20px;
    }

    .back-btn {
      position: fixed;
      top: 20px;
      right: 20px;
      z-index: 1000;
    }

    /* 状态分类选项卡样式 */
    .status-tabs {
      position: fixed;
      top: 20px;
      left: 50%;
      transform: translateX(-50%);
      width: 100%;
      max-width: 1200px;
      padding: 0 20px;
      z-index: 999;
    }

    .layui-tab {
      background: #fff;
      box-shadow: 0 2px 8px rgba(0,0,0,0.1);
      border-radius: 4px;
    }

    .layui-tab-content {
      margin-top: 0px;
    }
  </style>
</head>
<body>
<!-- 返回按钮 -->
<div class="back-btn">
  <a href="/toChina" class="layui-btn layui-btn-primary">返回首页</a>
</div>

<!-- 状态分类选项卡 -->
<div class="status-tabs">
  <div class="layui-tab">
    <ul class="layui-tab-title">
      <li class="layui-this">正常公告</li>
      <li>已关闭公告</li>
    </ul>
    <div class="layui-tab-content">
      <!-- 正常公告列表 -->
      <div class="layui-tab-item layui-show">
        <table class="layui-table" lay-even>
          <colgroup>
            <col width="20%">
            <col width="50%">
            <col width="20%">
            <col width="10%">
          </colgroup>
          <thead>
          <tr>
            <th>序号</th>
            <th>标题</th>
            <th>发布时间</th>
            <th>发布者</th>
          </tr>
          </thead>
          <tbody id="normalNoticeList">
          <tr th:each="notice : ${pastNoticeList}" th:if="${notice.status == '0'}">
            <td></td>
            <td><a th:href="@{/notice/detail/{id}(id=${notice.id})}" th:text="${notice.title}"></a></td>
            <td th:text="${#dates.format(notice.modifiedTime, 'yyyy-MM-dd HH:mm:ss')}"></td>
            <td th:text="${notice.modifiedUser}"></td>
          </tr>
          </tbody>
        </table>
      </div>
      <!-- 已关闭公告列表 -->
      <div class="layui-tab-item">
        <table class="layui-table" lay-even>
          <colgroup>
            <col width="20%">
            <col width="50%">
            <col width="20%">
            <col width="10%">
          </colgroup>
          <thead>
          <tr>
            <th>序号</th>
            <th>标题</th>
            <th>发布时间</th>
            <th>发布者</th>
          </tr>
          </thead>
          <tbody id="closedNoticeList">
          <tr th:each="notice : ${pastNoticeList}" th:if="${notice.status == '1'}">
            <td></td>
            <td><a th:href="@{/notice/detail/{id}(id=${notice.id})}" th:text="${notice.title}"></a></td>
            <td th:text="${#dates.format(notice.modifiedTime, 'yyyy-MM-dd HH:mm:ss')}"></td>
            <td th:text="${notice.modifiedUser}"></td>
          </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>

<script>
  layui.use('element', function() {
    var element = layui.element;
    element.render('tab'); // 初始化选项卡

    // 序号生成函数
    function generateSerialNumbers(tableId) {
      const tbody = document.getElementById(tableId);
      const rows = tbody.querySelectorAll('tr');
      rows.forEach((row, index) => {
        row.children[0].textContent = index + 1;
      });
    }

    // 初始化时生成序号
    generateSerialNumbers('normalNoticeList');
    generateSerialNumbers('closedNoticeList');

    // 选项卡切换时重新生成序号（可选）
    element.on('tab(status-tabs)', function(data) {
      generateSerialNumbers('normalNoticeList');
      generateSerialNumbers('closedNoticeList');
    });
  });
</script>
</body>
</html>